/*
  学习目标：掌握嵌套路由的设置
*/

import React from 'react';
import {
  BrowserRouter as Router,
  Route,
  NavLink,
  Switch,
  Redirect,
} from 'react-router-dom';
import './index.css';
import { Link } from 'react-router-dom';

export default class App extends React.Component {
  render() {
    return (
      <Router>
        <div>
          <h1>app组件</h1>
          <NavLink to="/home" exact>
            调到home
          </NavLink>
          <br />
          <NavLink to="/my">调到我的音乐</NavLink>
          <br />
          <NavLink to="/friend">调到朋友</NavLink>
          <Switch>
            <Redirect from="/" to="/home" exact />
            <Route path="/home" component={Home}></Route>
            <Route path="/home" component={Home}></Route>
            <Route path="/home" component={Home}></Route>
            <Route path="/home" component={Home}></Route>
            <Route path="/my" component={MyMusic}></Route>
            <Route path="/friend" component={Friend}></Route>
            <Route component={NotFount}></Route>
          </Switch>
        </div>
      </Router>
    );
  }
}

function Friend() {
  return (
    <div>
      <Link to="/friend">F1</Link>
      <br />
      <Link to="/friend/f2">F2</Link>
      <br />
      <Link to="/friend/f3">F3</Link>
      <h1>我是朋友组件</h1>
      {/*   
      步骤：
        1. 在父组件内，使用Switch + Route设置路由规则
      注意：
        1. 💥二级路由， path从"/一级路由/二级路由"
        2. 💥二级路由跳转：to="/一级路由/二级路由"跳转
        3. 父子级路由的path，可以同名，都会正常显示
        4. 父路由一般不能加exact
      */}
      <Switch>
        <Route path="/friend/f2" component={Friend2} />
        <Route path="/friend/f3" component={Friend3} />
        <Route path="/friend" component={Friend1} />
      </Switch>
    </div>
  );
}

function Friend1() {
  return <h1>我是朋友1组件</h1>;
}
function Friend2() {
  return <h2>我是朋友2组件</h2>;
}
function Friend3() {
  return <h3>我是朋友3组件</h3>;
}

function NotFount() {
  return <h1>...404..页面</h1>;
}

function Home() {
  return <h1>我是首页组件</h1>;
}

function MyMusic() {
  return <h1>我是我的音乐件</h1>;
}
